
#include "exportthreaddialog.h"

ExportThreadDialog::ExportThreadDialog(QWidget* parent) : QDialog(parent),
	m_factory(),
	m_config(0),
	m_ui(new Ui::ExportThreadDialog())
{
	m_ui->setupUi(this);
	m_ui->cb_builder->addItems(m_factory.availableBuilders());
	methodChanged(m_ui->cb_builder->currentText());
}

ExportThreadDialog::~ExportThreadDialog()
{
}

void ExportThreadDialog::accept()
{
	m_builder->applyConfig(m_config);
	QDialog::accept();
}

Wishmaster::ThreadBuilderPtr ExportThreadDialog::builder()
{
	return m_builder;
}

void ExportThreadDialog::methodChanged(const QString& method)
{
	QList<QObject*> children = m_ui->gb_config->children();
	foreach(QObject* obj, children)
	{
		delete obj;
	}
	m_builder = m_factory.builder(method);
	m_config = m_builder->createConfigWidget();
	if(m_config)
	{
		m_ui->gb_config->setLayout(new QBoxLayout(QBoxLayout::TopToBottom, m_ui->gb_config));
		m_config->setParent(m_ui->gb_config);
		m_ui->gb_config->layout()->addWidget(m_config);
		m_ui->gb_config->setVisible(true);
	}
	else
	{
		m_ui->gb_config->setVisible(false);
	}
}

